package com.mcflywzx.airhockey.util;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

import android.content.Context;
import android.content.res.Resources;

//加载资源中的文本
public class TextResourceReader {

	public static String readTextFileFromResource(Context context, int resourceId)
	{
		StringBuilder body = new StringBuilder();
		
		try{
			InputStream inputStream = 
					context.getResources().openRawResource(resourceId);
			InputStreamReader inputStreamReader =
					new InputStreamReader(inputStream);
			BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
			
			String nextLine;
			
			while((nextLine = bufferedReader.readLine()) != null){
				body.append(nextLine);
				body.append('\n');
			}
		} catch (IOException e) {
			throw new RuntimeException("无法打开资源: " + resourceId, e);
		} catch (Resources.NotFoundException nfe) {
			throw new RuntimeException("找不到资源: " + resourceId, nfe);
		}
		return body.toString();
	}
}
